/**
 * Created by ly on 2015/3/30.
 */
;
angular.module("loginApp",["ngCookies","angular-md5","ngMessages","loginFilter","helloDir"]).controller("LoginCtrl",
  function($scope, $http, $cookieStore, md5, $window){
  var clientId = $cookieStore.get("clientId");
  clientId = $.createClientId(clientId);
  $cookieStore.put("clientId",clientId);
  $scope.formData = {clientType:"BROWSER",clientId:clientId};
  var sign = $.signAlgorithm(configs.adminSignUrl + "loginByUserName",["appkey=" + configs.appKey],md5);
  var url = configs.adminServerUrl + "loginByUserName?appkey="+configs.appKey+"&sign="+sign;
  $scope.loginProcess = function(){
    $http({
      method : "POST",
      url : url,
      data : $.param($scope.formData),
      headers : {'Content-Type' : 'application/x-www-form-urlencoded'}
    }).success(function(data){
      if(data.status == "SUCCEED"){
        $cookieStore.put("token", data.token);
        $window.location.href = configs.rootUrl + "views/userRole.html";/**/
      }
    });
  }
 });

